package com.wz.jiangsu.main.lock;
/***
 * ReentrantLock可重入
 */

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

@Slf4j
public class TestReentrantLock1 {
    static ReentrantLock lock = new ReentrantLock();

    //方法lock1
    public static void lock1() throws Exception{
        try {
            lock.lock();
            log.debug("---------lock1执行---------");
            lock2();
        } finally {
            lock.unlock();
        }
    }

    //方法lock2
    public static void lock2()   {
        try {
            lock.lock();
            log.debug("---------lock2执行---------");
        } finally {
            lock.unlock();
        }
    }

    //测试
    public static void main(String[] args) throws Exception{
        lock1();
    }
}
